﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using EnvDTE;
using TSVNAddin.SVN;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class ItemActionExecutorFixture
	{
		[Test]
		public void OnItemAddedShouldAddFileOnVersionControl()
		{
			var projectItem = MockRepository.GenerateStub<ProjectItem>();
			projectItem.Stub(x => x.get_FileNames(0)).Return(@"c:\ciccio.cs");
			var addedAction = MockRepository.GenerateStub<PathAddedAction>(null, null);

			var itemActionExecutor = new ItemActionExecutor(addedAction, null, null);
			itemActionExecutor.NotifyAdded(projectItem);

			addedAction.AssertWasCalled(x => x.Execute(@"c:\ciccio.cs"));
		}

		[Test]
		public void OnItemRemovedShouldDeleteFileOnVersionControl()
		{
			var projectItem = MockRepository.GenerateStub<ProjectItem>();
			projectItem.Stub(x => x.get_FileNames(0)).Return(@"c:\ciccio.cs");
			var removedAction = MockRepository.GenerateStub<PathRemovedAction>((IVersionControl)null);

			var itemActionExecutor = new ItemActionExecutor(null, removedAction, null);
			itemActionExecutor.NotifyRemoved(projectItem);

			removedAction.AssertWasCalled(x => x.Execute(@"c:\ciccio.cs"));
		}

		[Test]
		public void OnItemRenamedShouldRenameFileOnVersionControl()
		{
			var projectItem = MockRepository.GenerateStub<ProjectItem>();
			projectItem.Stub(x => x.get_FileNames(0)).Return(@"c:\ciccio.cs");
			var renamedAction = MockRepository.GenerateStub<PathRenamedAction>(null, null);

			var itemActionExecutor = new ItemActionExecutor(null, null, renamedAction);
			itemActionExecutor.NotifyRenamed(projectItem, @"oldCiccio.cs");

			renamedAction.AssertWasCalled(x => x.Execute(@"c:\ciccio.cs", @"oldCiccio.cs"));
		}
	}
}
